package com.sunny.activiti.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sunny.activiti.common.entity.*;
import com.sunny.activiti.entity.SysDict;
import com.sunny.activiti.entity.SystemMenu;
import com.sunny.activiti.entity.TaskVo;
import com.sunny.activiti.service.ISystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: IndexController
 * @Description:
 * @Author: sunt
 * @Date: 2020/5/28 19:43
 * @Version 1.0
 **/
@RestController
public class IndexController {
    @Autowired
    private ISystemService systemService;

    @RequestMapping("/menu/list")
    public ResponseTableResult menuList(PageBean pageBean) {
        Page<SystemMenu> page = systemService.list(pageBean);
        return ResponseUtil.makeTableRsp(0, page.getTotal(), page.getRecords());
    }

    /**
     * 删除菜单
     *
     * @param id
     */
    @RequestMapping("/menu/getById")
    public ResponseResult<Object> getById(Integer id) {
        SystemMenu menu = systemService.getById(id);
        return ResponseUtil.makeOKRsp(menu);
    }

    /**
     * 删除菜单
     *
     * @param id
     */
    @RequestMapping("/menu/delMenu")
    public ResponseResult<Object> delMenu(Integer id) {
        systemService.delMenu(id);
        return ResponseUtil.makeOKRsp();
    }

    /**
     * 保存菜单
     *
     * @param menu
     */
    @PostMapping("/menu/saveOrUpdate")
    public ResponseResult<Object> saveOrUpdate(@RequestBody SystemMenu menu) {
        systemService.saveOrUpdate(menu);
        return ResponseUtil.makeOKRsp();
    }

    @RequestMapping("queryMenu")
    public Map<String, Object> queryMenu() {
        Map<String, Object> map = systemService.queryMenuList();
        return map;
    }

    @RequestMapping("querySysDict")
    public ResponseResult<List<SysDict>> querySysDict() {
        List<SysDict> sysDicts = systemService.querySysDictInfo(SysConstant.SYSTEM_CODE);
        return ResponseUtil.makeOKRsp(sysDicts);
    }
}
